package com.guguguweb.rpc.Test;


import com.guguguweb.rpc.Test.service.HelloService;
import com.guguguweb.rpc.Test.service.ResultData;
import com.guguguweb.rpc.Test.service.TroubleService;
import com.guguguweb.rpc.net.client.GuRpcClient;
import com.guguguweb.rpc.net.client.imp.NettyClient;
import com.guguguweb.rpc.net.client.proxy.GuRpcClientProxy;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class NettyClientTest {


    private static final Logger log = LoggerFactory.getLogger(NettyClientTest.class);

    public static void main(String[] args) {
        GuRpcClient client = new NettyClient();
        GuRpcClientProxy guRpcClientProxy = new GuRpcClientProxy(client);
        HelloService helloService = guRpcClientProxy.getProxy(HelloService.class);
        TroubleService troubleService = guRpcClientProxy.getProxy(TroubleService.class);
        log.info("开启远程RPC调用");
        try {
////            ArrayList<String> list = new ArrayList<>();
////            for(int i = 0 ;i < 10000; i++){
////                list.add(String.valueOf(10000-i));
////            }
////
////            List<String> list1 = troubleService.get(list);
//
//            log.info("{}",list);
//            for(int i = 0 ;i < 10000;i++){
//                String data = helloService.sendHello("你好" + i + ";");
//                log.info("{}",data);
//            }
            nThreadTest(helloService);

        }catch (Exception e){
            e.printStackTrace();
        }
        log.info("已经结束了");
    }


    public static void nThreadTest(HelloService helloService){
        Thread t1 = new Thread(()->{
            for(int i = 0 ;i < 3000;i++){
                String data = helloService.sendHello("你好" + i + ";");
                log.info("{}",data);
            }
        });
        Thread t2 = new Thread(()->{
            for(int i = 3000 ;i < 6000;i++){
                String data = helloService.sendHello("你好" + i + ";");
                log.info("{}",data);
            }
        });
        Thread t3 = new Thread(()->{
            for(int i = 6000 ;i < 9000;i++){
                String data = helloService.sendHello("你好" + i + ";");
                log.info("{}",data);
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
